<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('微信用户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>手机号：</label>
                            <input type="text" name="phoneNum"/>
                        </li>
                        <li>
                            <label>归属单位：</label>
                            <input type="text" name="shopCompany"/>
                        </li>
                        <li class="select-time">
                            <label>注册时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="WxUser:WxUser:add">-->
            <!--<i class="fa fa-plus"></i> 添加-->
            <!--</a>-->
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="WxUser:WxUser:edit">-->
            <!--<i class="fa fa-edit"></i> 修改-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="WxUser:WxUser:remove">
                <i class="fa fa-remove"></i> 删除
            </a>-->
            <!--   <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="WxUser:WxUser:export">
                   <i class="fa fa-download"></i> 导出
               </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
    <div class="modal inmodal fade" style="z-index:2041;" id="myModal5" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">添加积分</h4>
                </div>
                <div class="modal-body">
                    <input class="form-control" type="number" id="addJf" placeholder="请输入需要增加的积分数量">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary saveJF">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('WxUser:WxUser:edit')}]];
    var removeFlag = [[${@permission.hasPermi('WxUser:WxUser:remove')}]];
    var sexDatas = [[${@dict.getType('sys_user_sex')}]];
    var isVipDatas = [[${@dict.getType('is_vip')}]];
    var isAlShopDatas = [[${@dict.getType('is_al_shop')}]];
    var editPayNumber = [[${@permission.hasPermi('WxUser:WxUser:editPayNumber')}]];
    var prefix = ctx + "WxUser/WxUser";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            modalName: "微信用户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'null',
                    visible: false
                },
                {
                    field: 'nickName',
                    title: '昵称'
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sexDatas, value);
                    }
                },
                {
                    field: 'avater',
                    title: '头像',
                    formatter: function (value, row, index) {
                        return '<img style="border-radius: 50%;width: 50px;height: 50px" src="' + value + '">'
                    }
                },
                {
                    field: 'phoneNum',
                    title: '手机号'
                },
                {
                    field: 'jiFen',
                    title: '积分'
                },
                {
                    field: 'ownMoney',
                    title: '余额'
                },
                {
                    field: 'isAlShop',
                    title: '是否归属商家',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(isAlShopDatas, value);
                    }
                },
                {
                    field: 'shopCompany',
                    title: '归属单位'
                },
                {
                    field: 'createTime',
                    title: '注册时间'
                },

                {
                    title: '操作',
                    align: 'center',
                    visible: editFlag == "hidden"? false : true,
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.isAlShop!=0){
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="changeTerrace(\'' + row.id + '\')"><i class="fa fa-edit"></i>变更平台</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="changeBelongShop(\'' + row.id + '\')"><i class="fa fa-edit"></i>分配商家</a> ');
                        actions.push('<button class="btn btn-success btn-xs ' + editFlag + '"  data-toggle="modal" data-target="#myModal5" onclick="addJiFen(\'' + row.id + '\')"><i class="fa fa-edit"></i>增加积分</button> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + editPayNumber + '" href="javascript:void(0)" onclick="resetPayNum(\'' + row.id + '\')"><i class="fa fa-edit"></i>重置支付密码</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*归属到平台*/
    function changeTerrace(wxUserId) {
        $.modal.confirm("确认要将此用户变更归属到平台吗",function () {
            $.operate.post(prefix+"/changeTerrace",{wxUserId:wxUserId},function (result) {
                $.operate.successCallback(result);
            })
        })
    }
    /*归属到某个商家*/
    function changeBelongShop(wxUserId) {
        $.modal.openTab("选择归属商铺",prefix+"/selectShop/"+wxUserId)
    }
    /*重置用户支付密码*/
    function resetPayNum(wxUserId) {
        var url = prefix + "/resetPayNum/"+wxUserId;
        $.modal.open("修改密码", url, '800', '300');
    }
    /*增加积分*/
    var wxUserId ;
    function addJiFen(wid) {
        wxUserId =wid
    }
    $(".saveJF").on("click",function(){
        var JfNum = $("#addJf").val()
        if (!JfNum){
            $.modal.alertError("请输入积分");
            return false;
        }
        $.modal.confirm("确认给该会员增加积分吗",function () {
            $.operate.post(prefix+"/toAddJF",{wxUserId:wxUserId,JfNum:JfNum},function (result) {
                $.operate.successCallback(result);
            })
        })
    })
</script>
</body>
</html>